package com.x.bff.app.controller;

import com.x.bff.app.model.vo.directory.*;
import com.x.bff.app.service.customer.DirectoryService;
import com.x.core.utils.BeanUtil;
import com.x.core.web.api.R;
import com.x.core.web.controller.BaseFrontendController;
import com.x.provider.api.customer.model.dto.directory.AttributeDTO;
import com.x.provider.api.customer.model.dto.directory.AttributeRandomReqDTO;
import com.x.provider.api.customer.service.DirectoryRpcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "目录服务")
@Slf4j
@RestController
@RequestMapping("/app/directory")
public class DirectoryController extends BaseFrontendController {

    private final DirectoryService directoryService;
    private final DirectoryRpcService directoryRpcService;

    public DirectoryController(DirectoryService directoryService,
                               DirectoryRpcService directoryRpcService){
        this.directoryService = directoryService;
        this.directoryRpcService = directoryRpcService;
    }

    @ApiOperation(value = "查询区域信息")
    @PostMapping("/region/list")
    public R<List<RegionVO>> listRegion(@RequestBody @Validated RegionListReqVO regionListReq){
        List<RegionVO> result = directoryService.listRegion(regionListReq);
        return R.ok(result);
    }

    @ApiOperation(value = "查询属性信息,学历\tDEGREE\n" +
            "婚姻状态\tMARRIAGE_STATUS\n" +
            "月收入\tSALARY_MONTH\n" +
            "职业\tOCCUPATION\n" +
            "住房情况\tHOUSE\n" +
            "民族\tETHNICITY\n" +
            "体型\tSHAPE\n" +
            "孩子情况\tCHILDREN\n" +
            "星座\tCONSTELLATION\n" +
            "期望结婚日期\tEXPECT_WEDDING_DATE\n" +
            "性别\tGENDER\n" +
            "体型\tSHAPE_GIRL\n" +
            "吸引\tSMOKE\n" +
            "喝酒\tDRINK\n" +
            "想要小孩\tWANT_BABY\n" +
            "默认昵称（男）\tNICK_NAME_MAN\n" +
            "默认昵称（女）\tNICK_NAME_GIRL")
    @PostMapping("/attribute/list")
    public R<Map<String, AttributeVO>> logout(@RequestBody @Validated AttributeListReqVO attributeListReq){
        Map<String, AttributeVO> result = directoryService.listAttribute(attributeListReq);
        return R.ok(result);
    }

    @ApiOperation(value = "查询属性名下的随机属性值，可以用于查询随机昵称 NICK_NAME_MAN 男性随机昵称 NICK_NAME_GIRL 女性随机昵称")
    @PostMapping("/attribute/random")
    public R<List<AttributeValueVO>> randomAttribute(@ApiParam("属性名称") @RequestParam String name,
                                                     @ApiParam("总数量")  @RequestParam int count){
        List<AttributeDTO> result = directoryRpcService.randomAttribute(AttributeRandomReqDTO.builder().name(name).total(count).build()).getData();
        return R.ok(BeanUtil.prepare(result, AttributeValueVO.class));
    }
}
